#include<iostream>  
using namespace std;  

const int Max_size=10000;  
int father[Max_size],rank[Max_size];  

inline int Max(int a,int b)  
{  
    return a>b?a:b;  
}  

void Make_Set(int n)  
{  
    int i;  
    for(i=0;i<n;i++) {
        father[i]=i;
        rank[i]=1;
    }  
}  

int Find_Set(int x)  
{  
    int t=x;  
    int temp;  
    while(father[x]!=x)  
        x=father[x];  

    while(father[t]!=x)  
    {  
        temp=father[t];  
        father[t]=x;  
        rank[t]=1;  
        t=temp;  
    }
    return x;  
}  

void Union(int root1,int root2)  
{  
    int troot1=Find_Set(root1);  
    int troot2=Find_Set(root2);  

    if(troot1!=troot2) {  
        if(rank[troot1]<rank[troot2])  
            father[troot1]=troot2, rank[troot2]=Max(rank[troot1]+1,rank[troot2]);  
        else  
            father[troot2]=troot1, rank[troot1]=Max(rank[troot2]+1,rank[troot1]);
    }
    else {
        father[troot2] = troot1;
        rank[troot2] = Max(rank[troot1]+1, rank[troot2]);
    }
} 

#if 0
int main()  
{  
    return 0;  
}  
#endif
